let app = getApp()


const dateUtil = require('../../utils/dateUtil')
Page({
  data: {
    userInfo: {
      avatarUrl: 'https://ucenter.ldtd168.com/?ctl=Index&met=img&user_id=12127',
      name: '',
      gender: '男',
      age: 0,
      experience: 0,
    },
    jobStatusOptions: ['在职-暂不考虑', '在职-考虑机会', '离职-随时到岗'],
    statusIndex: 1,
    workExperiences: [
    ],
    educations: [
    ],
    skills: [],
	certificates: [],
	report: [],
	idCardFront: '',
	idCardBack: '',
  },
  onLoad() {
  	new app.ToastPannel();
  	
  	  var that = this
    // 加载保存的用户信息
  	that.requests();
  },
  requests:function(){
    var that = this
    var key = wx.getStorageSync('key')
    var uid = wx.getStorageSync('u')
    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Personal_Resume&met=resumeDetail&typ=json',
      method: 'GET',
      data: { k: key, u: uid },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.status == 200) {
  			const user_info = {
				  avatarUrl: res.data.data.user_info.avatarUrl,
				  name: res.data.data.user_info.userName,
				  gender: res.data.data.user_info.gender == 1 ? '女' : '男',
				  age: dateUtil.getYearDiff(res.data.data.user_info.birthDate),
				  experience: dateUtil.getYearDiff(res.data.data.user_info.workDate),
			}
  			that.setData({
  				userInfo: user_info,
				educations: res.data.data.education_info,
				workExperiences: res.data.data.job_info,
				idCardFront: res.data.data.idCardFront,
				idCardBack:  res.data.data.idCardBack,
				certificates: res.data.data.certification_info,
				report: res.data.data.report_info,
  			})
			
			console.log(that.data.educations)
        } else {
          that.show('数据加载失败')
        }
  
      }
    })
  },
  
  
	changeJobStatus(e) {
		this.setData({
			statusIndex: e.detail.value
		})
	},

	// 编辑基本信息
	  navigateToEditBasic() {
		wx.navigateTo({
		  url: '/pages/edit_basic/edit_basic?data=' + JSON.stringify(this.data.userInfo)
		})
	  },
	  bindEditExperience(e) {
		// 跳转到编辑工作经历页面
		const index = e.currentTarget.dataset.index
		wx.navigateTo({
		  url: '../edit_experience/edit_experience?index=' + index
		})
	  },
	  bindEditEducation(e) {
		// 跳转到编辑教育背景页面
		const index = e.currentTarget.dataset.index
		wx.navigateTo({
			url: '../edit_education/edit_education?index=' + index
		})
	  },

	  bindEditSkills(e) {
		// 跳转到编辑技能页面
		wx.navigateTo({
			url: '../edit_skill/edit_skill'
		})
	  },
    // 删除工作经历
    deleteExperience(e) {
      const index = e.currentTarget.dataset.index
      const experiences = this.data.workExperiences
      experiences.splice(index, 1)
      this.setData({ workExperiences: experiences })
    },
	
	 // 预览图片
	  previewImage(e) {
	    const currentIndex = e.currentTarget.dataset.index;
	    wx.previewImage({
	      current: this.data.imageList[currentIndex], // 当前显示图片的http链接
	      urls: this.data.imageList // 需要预览的图片http链接列表
	    });
	  },
	  
	  bindEditCard(e) {
	    // 跳转到实名认证页面
	  	wx.navigateTo({
	  	  url: '../edit_card/edit_card'
	  	})
	  },
		bindEditCredential(e) {
			// 跳转到服务资质页面
			wx.navigateTo({
				url: '../edit_personal_credential/edit_personal_credential'
			})
		},
		bindEditReport(e) {
			// 跳转到体检报告
			wx.navigateTo({
				url: '../edit_personal_report/edit_personal_report'
			})
		},
		bindPreview(e) {
			// 跳转到简历详情页面
			wx.navigateTo({
				url: '../resume_detail/resume_detail'
			})
		},
	  
	
	
})